package com.ck.jdbc.util;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

/**
 * 被连接池管理数据连接管道
 * @author CK
 *
 */
public class PooledConnection {

	// 封装物理真实管道，jdbc提供的管道
	private Connection connection;
	
	// 是否被任务占用
	private boolean isBusy = false;

	public PooledConnection(Connection connection, boolean isBusy) {
		super();
		this.connection = connection;
		this.isBusy = isBusy;
	}

	public Connection getConnection() {
		return connection;
	}

	public void setConnection(Connection connection) {
		this.connection = connection;
	}

	public boolean isBusy() {
		return isBusy;
	}

	public void setBusy(boolean isBusy) {
		this.isBusy = isBusy;
	}
	
	// 管道本身有一个释放的方法
	public void close() {
		this.isBusy = false;
	}
	
	// 自定义管道里面业务方法
	/**
	 * 创建connection
	 * 创建小车statement
	 * sql小车statement
	 * 总结关闭  由内到外关闭
	 * 
	 * @param sql
	 * @return ResultSet
	 */
	public ResultSet queryBySql(String sql) {
		Statement statement = null;
		ResultSet resultSet = null;
		try {
			statement = connection.createStatement();
			resultSet = statement.executeQuery(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return resultSet;
	}
}
